import 'package:json_annotation/json_annotation.dart';

part 'miffy_recipe_cloud_list_api.g.dart';

@JsonSerializable()
class RequestMiffyRecipeCloudListApi {
  final List<String> categoryIds = [];
  final List<String> cookTimes = [];
  final List<String> easyLevelDescList = [];
  final String keyWord = "";
  final String searchType;
  final String sourceType = "";

  final int pageNo;
  final String pageSize;
  final List<String> productIds;

  factory RequestMiffyRecipeCloudListApi.fromJson(Map<String, dynamic> json) =>
      _$RequestMiffyRecipeCloudListApiFromJson(json);

  RequestMiffyRecipeCloudListApi({
    required this.pageNo,
    required this.pageSize,
    required this.productIds,
    this.searchType = "1",
  });

  Map<String, dynamic> toJson() => _$RequestMiffyRecipeCloudListApiToJson(this);
}

@JsonSerializable()
class ResponseMiffyRecipeCloudListApi {
  final int total;
  final List<MiffyRecipeCloud>? recipeMenuVoList;

  ResponseMiffyRecipeCloudListApi(this.total, this.recipeMenuVoList);

  factory ResponseMiffyRecipeCloudListApi.fromJson(Map<String, dynamic> json) =>
      _$ResponseMiffyRecipeCloudListApiFromJson(json);

  Map<String, dynamic> toJson() =>
      _$ResponseMiffyRecipeCloudListApiToJson(this);
}

@JsonSerializable()
class MiffyRecipeCloud {
  @JsonKey(name: 'id', fromJson: _intFromJson, toJson: _intToJson)
  final String id;
  final int? likes;
  final String? mainImg;
  final String name;
  final int isControl;
  final int? cookType;
  final String videoPreviewUrl;
  final int? collectionNum;
  final int? isShowControl;
  final int? browseNum;
  final bool? isCollect;

  // 构造函数
  MiffyRecipeCloud({
    required this.id,
    required this.likes,
    required this.mainImg,
    required this.name,
    required this.isControl,
    required this.cookType,
    required this.videoPreviewUrl,
    required this.collectionNum,
    required this.isShowControl,
    required this.browseNum,
    required this.isCollect,
  });

  // 生成 fromJson 和 toJson 方法
  factory MiffyRecipeCloud.fromJson(Map<String, dynamic> json) =>
      _$MiffyRecipeCloudFromJson(json);
  Map<String, dynamic> toJson() => _$MiffyRecipeCloudToJson(this);

  static String _intFromJson(int json) => json.toString();
  static int _intToJson(String object) => int.tryParse(object) ?? 0;
}
